package plus.easydo.jdbc.base.sql.handler;

import cn.hutool.core.text.CharSequenceUtil;

/**
 * 默认名称处理handler
 * @author laoyu
 * @version 1.0
 */
public class DefaultNameHandler implements NameHandler {

    /** 驼峰转连接符后的连接符 */
    private static final char SYMBOL = '_';

    /**
     * 根据实体名获取表名
     *
     * @param entityName entityName
     * @return java.lang.String
     * @author laoyu
     */
    @Override
    public String getTableName(String entityName) {
        //Java属性的骆驼命名法转换回数据库下划线“_”分隔的格式
        return CharSequenceUtil.toSymbolCase(entityName,SYMBOL);
    }

    /**
     * 根据表名获取主键名
     *
     * @param entityName entityName
     * @return java.lang.String
     * @author laoyu
     */
    @Override
    public String getPrimaryName(String entityName) {
        return CharSequenceUtil.toSymbolCase(entityName,SYMBOL) + "_id";
    }

    /**
     * 根据属性名获取列名
     *
     * @param fieldName fieldName
     * @return java.lang.String
     * @author laoyu
     */
    @Override
    public String getColumnName(String fieldName) {
        return  CharSequenceUtil.toSymbolCase(fieldName,SYMBOL);
    }
}
